import java.util.ArrayList;
import java.util.List;

public class Manager extends Employee
{

	List<Employee> self;

	public Manager(Schedule schedule)
	{
		super(schedule);
		this.setName("Manager");
		self = new ArrayList<Employee>();
		self.add(this);
	}

	@Override
	public void scheduleDay()
	{
		// Arrives at 8 hours 0 minutes
		schedule.scheduleEvent(new ArriveToOffice(new Time(8, 0), this));

		// Manager always takes 60 minute lunch at noon
		schedule.scheduleEvent(new Lunch(new Time(12, 0), this,
			new TimeDuration(0, 60)));

		// Two executive hour meetings. At 10am and 2pm
		schedule.scheduleEvent(new Meeting(new Time(10, 0), self,
			new TimeDuration(1, 0), "Executive Meeting"));
		schedule.scheduleEvent(new Meeting(new Time(14, 0), self,
			new TimeDuration(1, 0), "Executive Meeting"));

		// Manager always last to leave at 5
		schedule.scheduleEvent(new LeaveOffice(new Time(17, 0), this));
	}
	
	public void run(){
		scheduleDay();
		while(true){
			//A little cheating for the end of the day, otherwise this code should be executed after the daily activities method
			if(eventsToExecute.peek() instanceof LeaveOffice){
				//Iterate through all the questions and tell them to go do something else
				//or try again
				for(Event e : eventsToExecute){
					if(e instanceof Question){
						Question q = (Question) e;
						q.retryQuestion();
					}
				}
			}
			try{
				dayLogistics();
			}catch(RuntimeException ex){
				break;
			}
			//Iterate through all the questions and tell them to go do something else
			//or try again
			for(Event e : eventsToExecute){
				if(e instanceof Question){
					Question q = (Question) e;
					q.retryQuestion();
				}
			}
		}
	}
}
